﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using Wicresoft.Common;
using JDEduTrain.Framework.Entity;
using JDEduTrain.Framework.Business;

public partial class Page_UserInfoDetail : BaseAuthenticationPage
{
    public Guid UserID
    {
        get
        {
            if (Request["UserID"] != null)
                return new Guid(Request["UserID"]);
            return Guid.Empty;
        }
    }

    private bool Manage
    {
        get
        {
            if (Request["Manage"] != null)
                return bool.Parse(Request["Manage"]);
            return false;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        this.UseTabber = true;
        if (!IsPostBack)
        {
            UserExtend userExtend = new UserExtend(UserID);
            if (userExtend.Load())
            {
                tbBirthday.Text = userExtend.Birthday.ToShortDateString();
                tbPositionLevel.Text = userExtend.PositionLevel;
                tbFullName.Text = userExtend.FullName;
                rblSex.SelectedValue = userExtend.Gender;
                tbThirdLevelDeptDisplayName.Text = userExtend.ThirdLevelDeptDisplayName;
                tbNativePlace.Text = userExtend.NativePlace;
                tbStation.Text = userExtend.Station;
                tbBackNvarchar1.Text = userExtend.BackNvarchar1;
                tbBackNvarchar2.Text = userExtend.BackNvarchar2;
                
            }
            if (!Manage)
            {
                trToolMenu.Visible = false;
                tbBackNvarchar1.ReadOnly = true;
                tbBackNvarchar2.ReadOnly = true;
                tbBirthday.Enabled = false;
                tbFullName.ReadOnly = true;
                rblSex.Enabled = false;
                tbThirdLevelDeptDisplayName.ReadOnly = true;
                tbNativePlace.ReadOnly = true;
                tbPositionLevel.ReadOnly = true;
                tbStation.ReadOnly = true;
                
            }

        }
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        UserExtend userExtend = new UserExtend(UserID);
        if(userExtend.Load())
        {
            userExtend.BackNvarchar1 = tbBackNvarchar1.Text;
            userExtend.BackNvarchar2 = tbBackNvarchar2.Text;
            try
            {
                userExtend.Birthday = Convert.ToDateTime(tbBirthday.Text);
            }
            catch (Exception)
            {
                userExtend.Birthday = DateTime.MinValue;
            }
            userExtend.FullName = tbFullName.Text;
            userExtend.Gender = rblSex.SelectedValue;
            userExtend.NativePlace = tbNativePlace.Text;
            userExtend.PositionLevel = tbPositionLevel.Text;
            userExtend.Station = tbStation.Text;
            userExtend.Save();
        }
    }
    protected void btnReset_Click(object sender, EventArgs e)
    {
        tbBackNvarchar1.Text = string.Empty;
        tbBackNvarchar2.Text = string.Empty;
        
    }
}
